package com.itbaima.csmall.cart.webapi.service.impl;

import com.itbaima.csmall.cart.webapi.mapper.CartMapper;
import com.itbaima.csmall.cart.service.CartService;
import com.itbaima.csmall.commons.pojo.cart.dto.CartAddDTO;
import com.itbaima.csmall.commons.pojo.cart.entity.Cart;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>购物车的业务实现类</p>
 *
 * @author Chen
 * @since 2023/2/20 10:43:43
 */
@Slf4j
@Service
@DubboService
public class CartServiceImpl implements CartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public void cartAdd(CartAddDTO cartAddDTO) {
        Cart cart = new Cart();
        BeanUtils.copyProperties(cartAddDTO, cart);
        cartMapper.insertCart(cart);
        log.info("新增购物车成功！{}", cart);
    }

    @Override
    public void deleteUserCart(String userId, String commodityCode) {
        cartMapper.deleteCartByUserIdAndCommodityCode(userId, commodityCode);
        log.info("删除购物成功！");
    }

}
